#include "Product.h"
#include <ace/INET_Addr.h>
#include <ace/Assert.h>
Producet::Producet()
: _reactor(0)
, _client_acceptor(0)
, _game_connector(0)
, _game_channel(0)
{
	_reactor = ACE_Reactor::instance();
	ACE_NEW(_client_acceptor,ClientAcceptor());
	ACE_NEW(_game_connector, GameConnector());

	ACE_NEW(_game_channel, GameHandler());
}

Producet::~Producet()
{
	delete _client_acceptor;
	delete _game_connector;
	delete _game_channel;
}

Producet*
Producet::instance()
{
	static Producet inst;
	return(&inst);
}

int
Producet::timer()
{
	return 0;
}

GameHandler *
Producet::game_channel()
{
	return _game_channel;
}

int
Producet::run()
{	
	if(-1 == _client_acceptor->open(ACE_INET_Addr("0.0.0.0:60000")))
	{
		ACE_DEBUG((LM_ERROR , ACE_TEXT("-1==_client_acceptor->open(ACE_INET_Addr(\"0.0.0.0:60000\"))\n")));
		ACE_ASSERT(0);
	}
	
	
	if(-1 == _game_connector->connect(_game_channel , ACE_INET_Addr("127.0.0.1:60001")))
	{
		ACE_DEBUG((LM_ERROR , ACE_TEXT("-1 == _game_connector->connect( GameHandler::instance() ,ACE_INET_Addr(\"127.0.0.1:60001\"))\n")));
		ACE_ASSERT(0);
	}
	
	_reactor->run_reactor_event_loop();

	return 0;
}

int
ACE_TMAIN(int, ACE_TCHAR **)
{
	return Producet::instance()->run();
}